package com.starinside.wp.foundation.vo;

import com.starinside.wp.domain.Children;
import com.starinside.wp.domain.ChildrenHealthBaseInfo;
import com.starinside.wp.utils.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/11/1
 * *******************************
 */
@Data
public class ChildChildrenHealthListVo {
    private String id;
    private String name;
    private String gender;
    private Integer times = 0;
    private Long lastEvaluated = 0L;

    public static ChildChildrenHealthListVo of(Children children, List<ChildrenHealthBaseInfo> healthBaseInfoList) {
        ChildChildrenHealthListVo vo = new ChildChildrenHealthListVo();
        vo.setId(children.getId());
        vo.setName(children.getName());
        vo.setGender(children.getGender() == 0 ? "女" : "男");
        if (Objects.nonNull(healthBaseInfoList)) {
            vo.setTimes(healthBaseInfoList.size());
            vo.setLastEvaluated(healthBaseInfoList.size() == 0 ? 0L : DateUtil.betweenDays(healthBaseInfoList.get(0).getEvaluateTime(), new Date()));
        }
        return vo;
    }
}
